import javax.swing.*;
import java.util.*;

public class GroupManagementSystem {

    public static void main(String[] args) {
        Map<String, List<String>> classes = new HashMap<>();
        Map<String, Map<String, Integer>> groups = new HashMap<>();
        Map<String, List<String>> students = new HashMap<>();

        while (true) {
            int option = showMainMenu();
            if (option == 5) break; // 退出程序
            switch (option) {
                case 1:
                    manageClasses(classes, students);
                    break;
                case 2:
                    manageGroups(groups, students);
                    break;
                case 3:
                    manageStudents(students);
                    break;
                case 4:
                    randomRollCall(classes, groups, students);
                    break;
                default:
                    JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
            }
        }
    }

    private static int showMainMenu() {
        Object[] options = {
                "1. 班级管理",
                "2. 小组管理",
                "3. 学生管理",
                "4. 随机点名",
                "5. 退出"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "主菜单",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null || selectedOption.equals("5. 退出")) {
            return 5; // 用户选择退出
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void manageClasses(Map<String, List<String>> classes, Map<String, List<String>> students) {
        int option = showClassManagementMenu();
        switch (option) {
            case 1:
                addClass(classes);
                break;
            case 2:
                manageClass(classes);
                break;
            case 3:
                listClasses(classes);
                break;
            case 4:
                addStudentToClass(classes, students);
                break;
            case 5:
                removeStudentFromClass(classes);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showClassManagementMenu() {
        Object[] options = {
                "1. 新增班级",
                "2. 维护班级",
                "3. 班级列表",
                "4. 添加学生到班级",
                "5. 从班级中移除学生"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "班级管理",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void addClass(Map<String, List<String>> classes) {
        String className = JOptionPane.showInputDialog("请输入班级名称:");
        if (className != null && !className.isEmpty()) {
            classes.put(className, new ArrayList<>());
            JOptionPane.showMessageDialog(null, "班级 " + className + " 已添加");
        } else {
            JOptionPane.showMessageDialog(null, "班级名称不能为空");
        }
    }

    private static void manageClass(Map<String, List<String>> classes) {
        if (classes.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有班级可以管理");
            return;
        }

        String[] classNames = classes.keySet().toArray(new String[0]);
        String selectedClass = (String) JOptionPane.showInputDialog(
                null,
                "请选择要管理的班级:",
                "管理班级",
                JOptionPane.QUESTION_MESSAGE,
                null,
                classNames,
                classNames[0]
        );

        if (selectedClass == null) {
            return;
        }

        int option = showClassMaintenanceMenu();
        switch (option) {
            case 1:
                renameClass(classes, selectedClass);
                break;
            case 2:
                deleteClass(classes, selectedClass);
                break;
            case 3:
                listStudentsInClass(classes, selectedClass);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showClassMaintenanceMenu() {
        Object[] options = {
                "1. 重命名班级",
                "2. 删除班级",
                "3. 查看班级学生列表"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "维护班级",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void renameClass(Map<String, List<String>> classes, String oldName) {
        String newName = JOptionPane.showInputDialog("请输入新的班级名称:");
        if (newName != null && !newName.isEmpty()) {
            List<String> students = classes.get(oldName);
            classes.remove(oldName);
            classes.put(newName, students);
            JOptionPane.showMessageDialog(null, "班级 " + oldName + " 已重命名为 " + newName);
        } else {
            JOptionPane.showMessageDialog(null, "班级名称不能为空");
        }
    }

    private static void deleteClass(Map<String, List<String>> classes, String className) {
        classes.remove(className);
        JOptionPane.showMessageDialog(null, "班级 " + className + " 已删除");
    }

    private static void listClasses(Map<String, List<String>> classes) {
        if (classes.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有班级");
            return;
        }

        StringBuilder sb = new StringBuilder("班级列表:\n");
        for (String className : classes.keySet()) {
            sb.append(className).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void listStudentsInClass(Map<String, List<String>> classes, String className) {
        List<String> students = classes.get(className);
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "班级 " + className + " 没有学生");
            return;
        }

        StringBuilder sb = new StringBuilder("班级 " + className + " 的学生列表:\n");
        for (String student : students) {
            sb.append(student).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void addStudentToClass(Map<String, List<String>> classes, Map<String, List<String>> students) {
        if (classes.isEmpty() || students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有班级或学生可以操作");
            return;
        }

        String[] classNames = classes.keySet().toArray(new String[0]);
        String selectedClass = (String) JOptionPane.showInputDialog(
                null,
                "请选择要添加学生的班级:",
                "添加学生到班级",
                JOptionPane.QUESTION_MESSAGE,
                null,
                classNames,
                classNames[0]
        );

        if (selectedClass == null) {
            return;
        }

        String[] studentNames = students.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要添加的学生:",
                "添加学生到班级",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        classes.get(selectedClass).add(selectedStudent);
        JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 已添加到班级 " + selectedClass);
    }

    private static void removeStudentFromClass(Map<String, List<String>> classes) {
        if (classes.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有班级可以操作");
            return;
        }

        String[] classNames = classes.keySet().toArray(new String[0]);
        String selectedClass = (String) JOptionPane.showInputDialog(
                null,
                "请选择要移除学生的班级:",
                "从班级中移除学生",
                JOptionPane.QUESTION_MESSAGE,
                null,
                classNames,
                classNames[0]
        );

        if (selectedClass == null) {
            return;
        }

        List<String> studentsInClass = classes.get(selectedClass);
        if (studentsInClass.isEmpty()) {
            JOptionPane.showMessageDialog(null, "班级 " + selectedClass + " 没有学生可以移除");
            return;
        }

        String[] studentNames = studentsInClass.toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要移除的学生:",
                "从班级中移除学生",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        studentsInClass.remove(selectedStudent);
        JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 已从班级 " + selectedClass + " 中移除");
    }

    private static void manageGroups(Map<String, Map<String, Integer>> groups, Map<String, List<String>> students) {
        int option = showGroupManagementMenu();
        switch (option) {
            case 1:
                addGroup(groups);
                break;
            case 2:
                manageGroup(groups, students);
                break;
            case 3:
                listGroups(groups);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showGroupManagementMenu() {
        Object[] options = {
                "1. 新增小组",
                "2. 维护小组",
                "3. 小组列表"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "小组管理",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void addGroup(Map<String, Map<String, Integer>> groups) {
        String groupName = JOptionPane.showInputDialog("请输入小组名称:");
        if (groupName != null && !groupName.isEmpty()) {
            groups.put(groupName, new HashMap<>());
            JOptionPane.showMessageDialog(null, "小组 " + groupName + " 已添加");
        } else {
            JOptionPane.showMessageDialog(null, "小组名称不能为空");
        }
    }

    private static void manageGroup(Map<String, Map<String, Integer>> groups, Map<String, List<String>> students) {
        if (groups.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有小组可以管理");
            return;
        }

        String[] groupNames = groups.keySet().toArray(new String[0]);
        String selectedGroup = (String) JOptionPane.showInputDialog(
                null,
                "请选择要管理的小组:",
                "管理小组",
                JOptionPane.QUESTION_MESSAGE,
                null,
                groupNames,
                groupNames[0]
        );

        if (selectedGroup == null) {
            return;
        }

        int option = showGroupMaintenanceMenu();
        switch (option) {
            case 1:
                renameGroup(groups, selectedGroup);
                break;
            case 2:
                deleteGroup(groups, selectedGroup);
                break;
            case 3:
                listStudentsInGroup(groups, selectedGroup);
                break;
            case 4:
                addStudentToGroup(groups, students, selectedGroup);
                break;
            case 5:
                removeStudentFromGroup(groups, selectedGroup);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showGroupMaintenanceMenu() {
        Object[] options = {
                "1. 重命名小组",
                "2. 删除小组",
                "3. 查看小组学生列表",
                "4. 添加学生到小组",
                "5. 从小组中移除学生"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "维护小组",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void renameGroup(Map<String, Map<String, Integer>> groups, String oldName) {
        String newName = JOptionPane.showInputDialog("请输入新的小组名称:");
        if (newName != null && !newName.isEmpty()) {
            Map<String, Integer> students = groups.get(oldName);
            groups.remove(oldName);
            groups.put(newName, students);
            JOptionPane.showMessageDialog(null, "小组 " + oldName + " 已重命名为 " + newName);
        } else {
            JOptionPane.showMessageDialog(null, "小组名称不能为空");
        }
    }

    private static void deleteGroup(Map<String, Map<String, Integer>> groups, String groupName) {
        groups.remove(groupName);
        JOptionPane.showMessageDialog(null, "小组 " + groupName + " 已删除");
    }

    private static void listGroups(Map<String, Map<String, Integer>> groups) {
        if (groups.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有小组");
            return;
        }

        StringBuilder sb = new StringBuilder("小组列表:\n");
        for (String groupName : groups.keySet()) {
            sb.append(groupName).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void listStudentsInGroup(Map<String, Map<String, Integer>> groups, String groupName) {
        Map<String, Integer> students = groups.get(groupName);
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "小组 " + groupName + " 没有学生");
            return;
        }

        StringBuilder sb = new StringBuilder("小组 " + groupName + " 的学生列表:\n");
        for (String student : students.keySet()) {
            sb.append(student).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void addStudentToGroup(Map<String, Map<String, Integer>> groups, Map<String, List<String>> students, String groupName) {
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有学生可以添加到小组");
            return;
        }

        String[] studentNames = students.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要添加的学生:",
                "添加学生到小组",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        groups.get(groupName).put(selectedStudent, 0); // 默认分数为0
        JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 已添加到小组 " + groupName);
    }

    private static void removeStudentFromGroup(Map<String, Map<String, Integer>> groups, String groupName) {
        Map<String, Integer> groupStudents = groups.get(groupName);
        if (groupStudents.isEmpty()) {
            JOptionPane.showMessageDialog(null, "小组 " + groupName + " 没有学生可以移除");
            return;
        }

        String[] studentNames = groupStudents.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要移除的学生:",
                "从小组中移除学生",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        groupStudents.remove(selectedStudent);
        JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 已从小组 " + groupName + " 中移除");
    }

    private static void manageStudents(Map<String, List<String>> students) {
        int option = showStudentManagementMenu();
        switch (option) {
            case 1:
                addStudent(students);
                break;
            case 2:
                manageStudent(students);
                break;
            case 3:
                listStudents(students);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showStudentManagementMenu() {
        Object[] options = {
                "1. 新增学生",
                "2. 维护学生",
                "3. 学生列表"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "学生管理",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void addStudent(Map<String, List<String>> students) {
        String studentName = JOptionPane.showInputDialog("请输入学生姓名:");
        if (studentName != null && !studentName.isEmpty()) {
            students.put(studentName, new ArrayList<>());
            JOptionPane.showMessageDialog(null, "学生 " + studentName + " 已添加");
        } else {
            JOptionPane.showMessageDialog(null, "学生姓名不能为空");
        }
    }

    private static void manageStudent(Map<String, List<String>> students) {
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有学生  以管理");
            return;
        }

        String[] studentNames = students.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要管理的学生:",
                "管理学生",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        int option = showStudentMaintenanceMenu();
        switch (option) {
            case 1:
                renameStudent(students, selectedStudent);
                break;
            case 2:
                deleteStudent(students, selectedStudent);
                break;
            case 3:
                viewStudentInfo(students, selectedStudent);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static int showStudentMaintenanceMenu() {
        Object[] options = {
                "1. 重命名学生",
                "2. 删除学生",
                "3. 查看学生信息"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "维护学生",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null) {
            return -1; // 用户取消了选择
        }

        for (int i = 0; i < options.length; i++) {
            if (options[i].equals(selectedOption)) {
                return i + 1; // 返回选项编号
            }
        }

        return -1; // 无效选项
    }

    private static void renameStudent(Map<String, List<String>> students, String oldName) {
        String newName = JOptionPane.showInputDialog("请输入新的学生姓名:");
        if (newName != null && !newName.isEmpty()) {
            List<String> info = students.get(oldName);
            students.remove(oldName);
            students.put(newName, info);
            JOptionPane.showMessageDialog(null, "学生 " + oldName + " 已重命名为 " + newName);
        } else {
            JOptionPane.showMessageDialog(null, "学生姓名不能为空");
        }
    }

    private static void deleteStudent(Map<String, List<String>> students, String studentName) {
        students.remove(studentName);
        JOptionPane.showMessageDialog(null, "学生 " + studentName + " 已删除");
    }

    private static void viewStudentInfo(Map<String, List<String>> students, String studentName) {
        List<String> info = students.get(studentName);
        if (info.isEmpty()) {
            JOptionPane.showMessageDialog(null, "学生 " + studentName + " 没有信息");
            return;
        }

        StringBuilder sb = new StringBuilder("学生 " + studentName + " 的信息:\n");
        for (String item : info) {
            sb.append(item).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void listStudents(Map<String, List<String>> students) {
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有学生");
            return;
        }

        StringBuilder sb = new StringBuilder("学生列表:\n");
        for (String student : students.keySet()) {
            sb.append(student).append("\n");
        }
        JOptionPane.showMessageDialog(null, sb.toString());
    }

    private static void randomRollCall(Map<String, List<String>> classes, Map<String, Map<String, Integer>> groups, Map<String, List<String>> students) {
        Object[] options = {
                "1. 随机抽取小组",
                "2. 随机在小组中抽取学生",
                "3. 随机在班级里抽取学生",
                "4. 给小组评分",
                "5. 记录学生考勤",
                "6. 记录学生答题情况",
                "7. 导出成绩",
                "8. 退出"
        };

        String selectedOption = (String) JOptionPane.showInputDialog(
                null,
                "请选择一个选项:",
                "随机点名",
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]
        );

        if (selectedOption == null || selectedOption.equals("8. 退出")) {
            return; // 用户选择退出
        }

        switch (selectedOption) {
            case "1. 随机抽取小组":
                // 实现随机抽取小组的逻辑
                break;
            case "2. 随机在小组中抽取学生":
                // 实现随机在小组中抽取学生的逻辑
                break;
            case "3. 随机在班级里抽取学生":
                // 实现随机在班级里抽取学生的逻辑
                break;
            case "4. 给小组评分":
                gradeGroup(groups);
                break;
            case "5. 记录学生考勤":
                recordAttendance(students);
                break;
            case "6. 记录学生答题情况":
                recordAnswer(students);
                break;
            case "7. 导出成绩":
                exportScores(classes, groups, students);
                break;
            default:
                JOptionPane.showMessageDialog(null, "无效的选项，请重新选择");
        }
    }

    private static void recordAttendance(Map<String, List<String>> students) {
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有学生可以记录考勤");
            return;
        }

        String[] studentNames = students.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要记录考勤的学生:",
                "记录考勤",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        String attendanceStatus = JOptionPane.showInputDialog("请输入考勤状态 (例如: 出勤, 迟到, 缺席):");
        if (attendanceStatus != null && !attendanceStatus.isEmpty()) {
            students.get(selectedStudent).add(attendanceStatus);
            JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 的考勤状态已记录: " + attendanceStatus);
        } else {
            JOptionPane.showMessageDialog(null, "考勤状态不能为空");
        }
    }

    private static void recordAnswer(Map<String, List<String>> students) {
        if (students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有学生可以记录答题情况");
            return;
        }

        String[] studentNames = students.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要记录答题情况的学生:",
                "记录答题情况",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        String answerStatus = JOptionPane.showInputDialog("请输入答题情况 (例如: 正确, 错误, 未作答):");
        if (answerStatus != null && !answerStatus.isEmpty()) {
            students.get(selectedStudent).add(answerStatus);
            JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 的答题情况已记录: " + answerStatus);
        } else {
            JOptionPane.showMessageDialog(null, "答题情况不能为空");
        }
    }

    private static void gradeGroup(Map<String, Map<String, Integer>> groups) {
        if (groups.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有小组可以评分");
            return;
        }

        String[] groupNames = groups.keySet().toArray(new String[0]);
        String selectedGroup = (String) JOptionPane.showInputDialog(
                null,
                "请选择要评分的小组:",
                "给小组评分",
                JOptionPane.QUESTION_MESSAGE,
                null,
                groupNames,
                groupNames[0]
        );

        if (selectedGroup == null) {
            return;
        }

        Map<String, Integer> groupScores = groups.get(selectedGroup);
        if (groupScores.isEmpty()) {
            JOptionPane.showMessageDialog(null, "小组 " + selectedGroup + " 没有学生可以评分");
            return;
        }

        String[] studentNames = groupScores.keySet().toArray(new String[0]);
        String selectedStudent = (String) JOptionPane.showInputDialog(
                null,
                "请选择要评分的学生:",
                "给学生评分",
                JOptionPane.QUESTION_MESSAGE,
                null,
                studentNames,
                studentNames[0]
        );

        if (selectedStudent == null) {
            return;
        }

        String scoreStr = JOptionPane.showInputDialog("请输入学生的分数:");
        try {
            int score = Integer.parseInt(scoreStr);
            groupScores.put(selectedStudent, score);
            JOptionPane.showMessageDialog(null, "学生 " + selectedStudent + " 的分数已更新为 " + score);
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(null, "输入的分数无效，请输入一个整数");
        }
    }

    private static void exportScores(Map<String, List<String>> classes, Map<String, Map<String, Integer>> groups, Map<String, List<String>> students) {
        if (classes.isEmpty() || groups.isEmpty() || students.isEmpty()) {
            JOptionPane.showMessageDialog(null, "没有数据可以导出");
            return;
        }

        StringBuilder sb = new StringBuilder("成绩导出:\n");

        for (String className : classes.keySet()) {
            sb.append("班级: ").append(className).append("\n");
            for (String student : classes.get(className)) {
                sb.append("  学生: ").append(student).append("\n");
                for (String groupName : groups.keySet()) {
                    Map<String, Integer> groupScores = groups.get(groupName);
                    if (groupScores.containsKey(student)) {
                        sb.append("    小组: ").append(groupName).append(", 分数: ").append(groupScores.get(student)).append("\n");
                    }
                }
            }
        }

        JOptionPane.showMessageDialog(null, sb.toString());
    }
}
